package com.tencent50.easy;

/**
 * @author zhengTao
 * @version 1.0
 * @description: 二叉树最大深度
 * @date 2022/7/24 14:35
 */
public class Demo09 {
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(int val) { this.val = val; }
        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    public int maxDepth(TreeNode root) {
         if(root==null){
             return 0;
         }
         if(root.left==null&&root.right==null){
             return 1;
         }else {
             return Math.max(maxDepth(root.left),maxDepth(root.right))+1;
         }
    }

}


